﻿using System;
using Windows.ApplicationModel.Resources;
using Windows.UI.Xaml.Data;

namespace Microsoft.PlayerFramework
{
    /// <summary>
    /// IValueConverter implementation used to return and format a resource.
    /// The value determines the format and the param determines the resource file key.
    /// </summary>
    public class ResourceConverter : IValueConverter
    {
        /// <inheritdoc /> 
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var format = value as string;
            var key = parameter as string;
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) return key;

            return new ResourceLoader("Microsoft.PlayerFramework").GetString(string.Format(format, key));
        }

        /// <inheritdoc /> 
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
